﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FeedbackNetwork.UI
{
    public partial class TrainPanel : Form
    {
        private static LinkedList<String> infos = new LinkedList<string>();

        public static void AddLoss(float loss, int epoch, int trained, int sum, float accuracy)
        {
            String s = "Epoch: " + epoch.ToString() + ", ";
            s = s + "trained: " + trained.ToString() + "/" + sum.ToString() + ", ";
            s = s + "Loss: " + loss.ToString() + ", ";
            s = s + "Accuracy: " + accuracy.ToString();
            infos.AddFirst(s);
            if (infos.Count > 100)
            {
                infos.RemoveLast();
            }
        }
        public TrainPanel()
        {
            InitializeComponent();
            this.update_timer.Interval = 20;
            this.update_timer.Enabled = true;
        }

        private void start_train_button_Click(object sender, EventArgs e)
        {
            this.loss_line.Clear();
            if (Program.train_start == false)
            {
                Thread model_thread = new Thread(Program.StartTrain);
                model_thread.Start();
            }
            Program.train_start = true;
            this.update_timer.Start();
        }

        private void stop_train_button_Click(object sender, EventArgs e)
        {
            Program.train_start = false;
            this.update_timer.Stop();
        }

     
        private void update_timer_Tick(object sender, EventArgs e)
        {
            this.loss_line.Lines = infos.ToArray();
        }
    }
}
